from django.shortcuts import render
from django.views import View
from apps.contents.utils import get_categories
from apps.contents.models import ContentCategory


class IndexView(View):
    def get(self,request):
        # 查询商品频道和分类
        categories = get_categories()
        #　广告楼层数据
        contents = {}
        # 先查询分类信息
        contents_categories = ContentCategory.objects.all()
        # 遍历
        for cat in contents_categories:
            contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')
        context = {
            "categories": categories,
            "contents": contents
        }
        return render(request,'index.html',context=context)